package com.focusai.efairy.ui.adapter.dev;

import android.content.Context;

import com.focusai.efairy.R;
import com.focusai.efairy.model.response.DevConfigResponse;
import com.focusai.efairy.ui.adapter.base.BaseRecyclerAdapter;
import com.focusai.efairy.ui.adapter.base.BaseRecyclerViewHolder;
import com.focusai.efairy.utils.PrUtils;

/**
 * Created by luo_guangwen on 2017/10/25.
 */

public class DevConfigAdapter extends BaseRecyclerAdapter<DevConfigResponse.DevSetting> {


    public DevConfigAdapter(Context context) {
        super(context);
    }

    @Override
    protected int getItemLayoutId() {
        return R.layout.item_dev_config;
    }

    @Override
    protected void onBindBaseRecyclerViewHolder(final BaseRecyclerViewHolder holder, final int position) {
        DevConfigResponse.DevSetting dataItem = mList.get(position);
        String lable = "";
        String value = "";
        if (dataItem.cid == 0) {
            if (dataItem.localType == 1) {
                lable = "心跳间隔";
                value = dataItem.heartbeat_interval_andio + "s";
            } else if (dataItem.localType == 2) {
                lable = "音响模式";
                if (dataItem.heartbeat_interval_andio == 0x01) {
                    value = "正常";
                } else {
                    value = "静音";
                }
            }
        } else {
            String text = PrUtils.getNameByPt(dataItem.pt) + "通道" + dataItem.cid;
            if (dataItem.pt == 128) {
                value = PrUtils.getInJianCeStateByHtv(dataItem.thv);
                if (dataItem.cid == 9){
                    text="烟感探测1";
                }else if (dataItem.cid == 10){
                    text="气体探测2";
                }
            } else if (dataItem.pt == 129) {
                value = PrUtils.getOutJianCeStateByHtv(dataItem.thv);
            } else {
                String unitByPt = PrUtils.getUnitByPt(dataItem.pt);
                float rateByPt = PrUtils.getRateByPt(dataItem.pt);
//                value =  (dataItem.thv * rateByPt) + unitByPt;
//                value = dataItem.thv + unitByPt;
                value = PrUtils.getRountByPt(dataItem.thv * rateByPt, dataItem.pt) + unitByPt;
            }
            lable = text;
        }
        holder.setText(R.id.text_lable, lable);
        holder.setText(R.id.text_value, value);
    }

}

